'''
Created on Feb 29, 2012

@author: Johnathon
'''
from Gates.Gate import Gate
from LineValues import One, Zero

class AndGate(Gate):
    '''
    classdocs
    '''
#    outputTable = {"X": {"X":"X", "1":"X", "0":"0", "D":"X", "D'":"X"},
#                   "1": {"X":"X", "1":"1", "0":"0", "D":"D", "D'":"D'"},
#                   "0": {"X":"0", "1":"0", "0":"0", "D":"0", "D'":"0"},
#                   "D": {"X":"X", "1":"D", "0":"0", "D":"D", "D'":"0"},
#                   "D'": {"X":"X", "1":"D'", "0":"0", "D":"0", "D'":"D'"},
#                   }
            

    def __init__(self, gateName, level, inputLines, outputLine):
        '''
        Constructor
        '''
        super(AndGate, self).__init__(gateName, level, inputLines, outputLine)
#        Gate.__init__(self, gateName, level, inputLines, outputLine)
#        self.gateName = gateName
#        self.level = level
#        self.inputs = inputLines
#        self.output = outputLine
    
    def evaluate(self):
        result = One
        for inputVal in self.inputs:
            result = inputVal.value.AND(result)
#            if inputVal.value == "0":
#                result = "0"
#                break
#            result = AndGate.outputTable[result][inputVal.value]
        if self.output is not None:
            self.output.driveValue(result)
            
    def getEquivalentFaults(self):
        faults = [(i, Zero) for i in self.inputs]
        faults.append((self.output, Zero))
        return [faults]
        
        
        
        
        
        
        
        